/****************************************Copyright (c)****************************************************
 
**--------------File Info---------------------------------------------------------------------------------
** File name:                at32f415_wk_config.h
** Last modified Date:       2024.08.07
** Last Version:             Ver:1.0
** Descriptions:             
**                        
**--------------------------------------------------------------------------------------------------------
** Created by:               adm
** Created date:             2024.08.07
** Version:                  Ver:1.0
** Descriptions:             
**--------------------------------------------------------------------------------------------------------*/

/*
Copyright (c) [2024]     [BA6IV  ]   [SINEWAVE] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan
PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

/* define to prevent recursive inclusion -----------------------------------*/
#ifndef __AT32F415_WK_CONFIG_H
#define __AT32F415_WK_CONFIG_H

#ifdef __cplusplus
extern "C" {
#endif

/* includes -----------------------------------------------------------------------*/
#include "at32f415.h"
#include "at32f415_board.h"
#include "sinewave.h"
#include "key.h"
#include "button.h"
#include "ssd1306.h"
#include "ssd1306_fonts.h"
#include "ssd1306_tests.h"

/* FreeRTOS includes */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

/* add user code begin dma define */
/* user can only modify the dma define value */
#define DMA1_CHANNEL1_BUFFER_SIZE   256
#define DMA1_CHANNEL1_MEMORY_BASE_ADDR   (uint32_t)sin_data
//#define DMA1_CHANNEL1_PERIPHERAL_BASE_ADDR  0

#define DMA1_CHANNEL2_BUFFER_SIZE   0
#define DMA1_CHANNEL2_MEMORY_BASE_ADDR   0
//#define DMA1_CHANNEL2_PERIPHERAL_BASE_ADDR   0

#define DMA1_CHANNEL3_BUFFER_SIZE   0
#define DMA1_CHANNEL3_MEMORY_BASE_ADDR   0
//#define DMA1_CHANNEL3_PERIPHERAL_BASE_ADDR   0

#define Button1_PIN         GPIO_PINS_3
#define Button1_GPIO_PORT   GPIOA
#define Read_Button1()      gpio_input_data_bit_read(Button1_GPIO_PORT, Button1_PIN)

#define Button2_PIN         GPIO_PINS_4
#define Button2_GPIO_PORT   GPIOA
#define Read_Button2()      gpio_input_data_bit_read(Button2_GPIO_PORT, Button2_PIN)

#define Button3_PIN         GPIO_PINS_5
#define Button3_GPIO_PORT   GPIOA
#define Read_Button3()      gpio_input_data_bit_read(Button3_GPIO_PORT, Button3_PIN)

/* Private defines -------------------------------------------------------------*/
//按键状态标志位  0:无效   1：按键有效
extern __IO uint8_t		button1_SINGLE_Click_Flag;
extern __IO uint8_t		button1_DOUBLE_Click_Flag;
extern __IO uint8_t		button1_LONG_PRESS_Flag;
extern __IO uint8_t		button1_LONG_PRESS_HOLD_Flag;

extern __IO uint8_t		button2_SINGLE_Click_Flag;
extern __IO uint8_t		button2_DOUBLE_Click_Flag;
extern __IO uint8_t		button2_LONG_PRESS_Flag;
extern __IO uint8_t		button2_LONG_PRESS_HOLD_Flag;

extern __IO uint8_t		button3_SINGLE_Click_Flag;
extern __IO uint8_t		button3_DOUBLE_Click_Flag;
extern __IO uint8_t		button3_LONG_PRESS_Flag;
extern __IO uint8_t		button3_LONG_PRESS_HOLD_Flag;

extern struct Button button1;			//定义按钮结构体
extern struct Button button2;			//定义按钮结构体
extern struct Button button3;			//定义按钮结构体

/* exported functions ------------------------------------------------------- */
  /* system clock config. */
  void wk_system_clock_config(void);

  /* config periph clock. */
  void wk_periph_clock_config(void);

  /* config systick and enable interrupt */
  uint32_t systick_interrupt_config(uint32_t ticks);

  /* init debug function. */
  void wk_debug_config(void);

  /* nvic config. */
  void wk_nvic_config(void);

  /* init gpio function. */
  void wk_gpio_config(void);

  /* init i2c1 function. */
  void wk_i2c1_init(void);

  /* init tmr1 function. */
  void wk_tmr1_init(void);
  
  /* init tmr11 function. */
  void wk_tmr11_init(void);

  /* init dma1 channel1 */
  void wk_dma1_channel1_init(void);

  /* init dma1 channel2 */
  void wk_dma1_channel2_init(void);

  /* init dma1 channel3 */
  void wk_dma1_channel3_init(void);

  /* config dma channel transfer parameter */
  /* user need to modify parameters memory_base_addr and buffer_size */
  void wk_dma_channel_config(dma_channel_type* dmax_channely, uint32_t peripheral_base_addr, uint32_t memory_base_addr, uint16_t buffer_size);

/* add user code begin exported functions */
    void user_button_init(void);
/* add user code end exported functions */

#ifdef __cplusplus
}
#endif

#endif
